<?php
/**
 * 用户等级
 */
namespace app\common\model;

use think\Model;

class MemberLevel extends Model
{
    protected $name = 'member_level';

    /**
     * 等级详情
     * @param $level_id 等级 ID
     * @return MemberLevel|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getDetails($level_id){
        $data = self::where('id',$level_id)->find();
        if(empty($data)) $data = self::getDefault();
        return $data;
    }

    /**
     * 等级详情
     * @param $level_id 等级级别
     * @return MemberLevel|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getLevelDetails($level){
        $data = self::where('level',$level)->find();
        return $data;
    }

    /**
     * 获取用户默认等级
     * @return MemberLevel|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getDefault(){
        $data = self::where('level','0')->find();
        return $data;
    }

    /**
     * 查询用户等级表
     * @return array
     */
    public static function getMemberList(){
        return self::select()->toArray();
    }

}